package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.ChildrenNameId;
import com.woniuxy.mesboot.mapper.NameIdMapper;
import com.woniuxy.mesboot.service.EmpService;
import com.woniuxy.mesboot.util.Result;
import com.woniuxy.mesboot.vo.EmpVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/emps")
public class EmpController {
    private static Map<String, Object> map = new HashMap<>();
    @Resource
    private NameIdMapper nameIdMapper;
    @Resource
    private EmpService empService;

    @GetMapping("{no}")
    public Result queryByNo(@PathVariable String no) {
        EmpVO vo = empService.selectByWorkNo(no);
        if (vo != null) {
            return Result.ok().data("emp", vo);
        }
        return Result.error().message("未找到该员工信息");
    }

    @PostMapping("{id}")
    public Result getNameIdOfFLR(@PathVariable Long id) {
        List<ChildrenNameId> nameIdList = nameIdMapper.getNameIdOfFLR(id);
        map.clear();
        map.put("vos", nameIdList);
        return Result.ok().data(map);
    }
}
